Utilisateur:Dr Brains/CollapseSidebox.js
Apparence
Note : après avoir enregistré la page, vous devrez forcer le rechargement complet du cache de votre navigateur pour voir les changements.
Mozilla / Firefox / Konqueror / Safari : maintenez la touche Majuscule (Shift) en cliquant sur le bouton Actualiser (Reload) ou pressez Maj-Ctrl-R (Cmd-R sur Apple Mac) ;
Chrome / Internet Explorer / Opera : maintenez la touche Ctrl en cliquant sur le bouton Actualiser ou pressez Ctrl-F5./**********************************************************************/
/* Panneaux de la barre de navigation gauche enroulables */
/* */
/* Issu de : */
/* http://fr.wikibooks.org/wiki/MediaWiki:Gadget-CollapseSidebox.js */
/* */
/* à appeler après les scripts créant des nouveaux panneaux */
/* */
/* {{Projet:JavaScript/Script}} */
/**********************************************************************/
// Style Panneaux //
var ArrondiCollapseSidebox = '0.5em';
mw.loader.addStyleTag(''
+ '.CollapsiblePortlet {'
+ '-moz-border-radius-topright: '+ArrondiCollapseSidebox+';'
+ '-moz-border-radius-topleft: '+ArrondiCollapseSidebox+';'
+ '-moz-border-radius-bottomright: '+ArrondiCollapseSidebox+';'
+ '-moz-border-radius-bottomleft: '+ArrondiCollapseSidebox+';'
+ '-moz-background-clip:border !important;'
+ '-moz-background-inline-policy:continuous !important;'
+ '-moz-background-origin:padding !important;'
+ 'background:#E0E3E6 none repeat scroll 0 0 ;'
+ 'border:thin solid silver ;'
+ 'font-variant:normal !important;'
+ 'text-transform:non !important;'
+ 'margin-left:0.2em; !important;'
+ '} '
+ '.CollapsiblePortlet h5 {'
+ 'font-weight: bold !important;'
+ 'border:none !important;'
+ 'background:none !important;'
+ '} '
+ '.CollapsiblePortletLink {'
+ 'float:right !important;'
+ 'margin-right:0.5em !important;'
+ '} '
+ '.CollapsiblePortlet div {'
+ '-moz-border-radius-topright: '+ArrondiCollapseSidebox+';'
+ '-moz-border-radius-topleft: '+ArrondiCollapseSidebox+';'
+ '-moz-border-radius-bottomright: '+ArrondiCollapseSidebox+';'
+ '-moz-border-radius-bottomleft: '+ArrondiCollapseSidebox+';'
+ '} '
+ '#p-logo {'
+ 'background:none !important;'
+ 'border:none !important;'
+ '} '
+ '');
/**
* Fonctions de traitement de chaînes
*/
function equalsAa(str1, str2) {
return str1.toUpperCase() == str2.toUpperCase();
}
function startsWithAa(string, prefix) {
return equalsAa(string.substring(0, prefix.length), prefix);
}
function substractPrefixAa(string, prefix) {
return startsWithAa(string, prefix) ? string.substring(prefix.length) : string;
}
function endsWithAa(string, prefix) {
return (string.length>=prefix.length) &&
equalsAa(string.substring(string.length-prefix.length), prefix);
}
function substractSuffixAa(string, prefix) {
return endsWithAa(string, prefix) ? string.substring(0,string.length-prefix.length) : string;
}
function startsWith(string, prefix) {
return string.substring(0, prefix.length) == prefix;
}
function substractPrefix(string, prefix) {
return startsWith(string, prefix) ? string.substring(prefix.length) : string;
}
function endsWith(string, prefix) {
return (string.length>=prefix.length) &&
(string.substring(string.length-prefix.length) == prefix);
}
function substractSuffix(string, prefix) {
return endsWith(string, prefix) ? string.substring(0,string.length-prefix.length) : string;
}
/**
* Écriture cookie : expire après 1 année par défaut
*/
function SetVar(name,value) {
var expires=new Date();
if (typeof(CookiesLifeTimeYears)=="undefined") CookiesLifeTimeYears=1;
expires.setFullYear(expires.getFullYear()+CookiesLifeTimeYears);
document.cookie=name+"="+escape(value)+
";expires="+expires.toGMTString()+";path=/";
}
/**
* Lecture cookie, valeur par défaut : paramètre defvalue
*/
function GetVar(name,defvalue) {
var s=";"+document.cookie.replace(/ /g,"")+";";
var i=s.indexOf(";"+name+"=");
if (i<0) return defvalue;
i+=name.length+2;
return unescape(s.substring(i,s.indexOf(";",i)));
}
/**
* Récupère la valeur du cookie
*/
function getCookieVal(name){
return GetVar(name,false);
}
function devdebug(msg){
if (typeof(_devdebug)=="function") _devdebug(msg);
}
function findPorlet(id){
for(var i in collapsed_porlets)
if (collapsed_porlets[i]==id) return i;
return -1;
}
function portletSwitch(idnode){
var node=document.getElementById("body"+idnode);
var opened = (node.style.display == "none");
node.style.display = opened ? "block" : "none";
node=document.getElementById("l"+idnode);
node.firstChild.data = opened?" ⇧":" ⇩";
var ti=findPorlet(idnode);
if (!opened) {if (ti<0) collapsed_porlets.push(idnode);}
else if (ti>=0) collapsed_porlets.splice(ti,1);
SetVar("collapsed_porlets",collapsed_porlets.join("/"));
return false;
}
var anon_id=0;
function collapsePortlet(node){
var name=node.getAttribute("id") || ""+(++anon_id);
var opened = 1; // Etat initial des menus : 1 = ouvert ; 0 = fermé
for(var i in collapsed_porlets)
if (collapsed_porlets[i]===name) {opened=0;break;}
var alink=document.createElement("a");
alink.setAttribute("id","l"+name);
alink.setAttribute("class","CollapsiblePortletLink");
alink.setAttribute("href","#");
alink.setAttribute("onclick","return portletSwitch('"+name+"');");
if (document.all){
alink.onclick = function(){
return portletSwitch(name);
}
}
alink.appendChild(document.createTextNode(opened?" ⇧":" ⇩"));
for ( var PChild = node.firstChild;
PChild != null;
PChild = PChild.nextSibling )
if ( $(PChild).hasClass('pBody') )
{
PChild.setAttribute("id","body"+name);
if (!opened) PChild.style.display = 'none';
}
else if ( equalsAa(PChild.nodeName,"h5") )
{
PChild.setAttribute("id","t"+name);
PChild.insertBefore(alink, PChild.firstChild);
}
}
var v_collapsed_porlets=GetVar("collapsed_porlets","");
if ( v_collapsed_porlets != "" ) collapsed_porlets = v_collapsed_porlets.split("/");
if ( typeof ( collapsed_porlets ) == "undefined" )
collapsed_porlets=[]; /* Par défaut */
function collapsePortlets(){
var content = document.getElementById("column-content");
var tabs = document.getElementById("p-cactions");
if((tabs)&&(content)){
tabs.parentNode.removeChild(tabs);
content.insertBefore(tabs,content.firstChild);
tabs.setAttribute("style", "position: absolute;z-index:100;top:1.2em;");
}
var Persotabs = document.getElementById("p-personal");
if((Persotabs)&&(content)){
Persotabs.parentNode.removeChild(Persotabs);
content.insertBefore(Persotabs,content.firstChild);
Persotabs.setAttribute("style", "position: absolute;z-index:150;top:0;");
}
var Column = document.getElementById("column-one");
if(!Column) Column = document.getElementById("panel");
if(!Column) Column = document.getElementById("mw_portlets");
if(!Column)return;
var portlets = Column.getElementsByTagName("div");
for(i=0;i<portlets.length;i++){
if ($(portlets[i]).hasClass("portlet")){
var PortletId = portlets[i].getAttribute("id");
if((PortletId != "p-personal")&&(PortletId != "p-cactions")&&(PortletId != "p-logo")){
collapsePortlet(portlets[i]);
$(portlets[i]).addClass("CollapsiblePortlet");
}
}
}
}
$(collapsePortlets);